
import React from 'react'
import { useDispatch, useSelector } from 'react-redux/es/exports'
import { decreatment, increatment } from '../../store/slices/countSlice'
export default function Count() { 
  const dispatch = useDispatch()
  const count = useSelector((state)=>{
     return state.count.count
  })

  // useSelector的参数是个回调函数 回调函数中接收的参数是store
  const movieList = useSelector((state)=>{
      // console.log(state); 
      return state.movie.movieList
  })

    const inCreatmenthandle =()=>{
      dispatch(increatment(10))
      
    }
    const deCreatmenthandle =()=>{
      dispatch(decreatment(1))
    }
    const inOddCreatmenthandle =()=>{
        if(count % 2 !== 0){
          dispatch(increatment(5))
        }
    }
 
  return (
    <div>
        <h1>我是Count组件 我的数量是{count}</h1>
        <h5>周末电影电影数量：{movieList.length}</h5>
        <button onClick={inCreatmenthandle}>累加</button>
        <button onClick={deCreatmenthandle}>累减</button>
        <button onClick={inOddCreatmenthandle}>基数添加</button>
        {/* <button onClick={inTimeouthandle}>延迟添加</button> */}
    </div>
  )
}
